/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Numpad.java
 *
 * Created on Nov 11, 2011, 3:16:59 PM
 */
package jccflux;

import java.awt.Color;
import java.awt.ComponentOrientation;
import javax.swing.JFrame;

/**
 *
 * @author MrYoso
 */
public class Numpad extends javax.swing.JFrame {

    /** Creates new form Numpad */
    public Numpad() {
        initComponents();
        reset();
        
    }
    public void reset()
    {
        //custcode checkbox event--------------
        txtA_custCode.setEnabled(false);
        txt_display.setEnabled(true);
        btn_refresh.setEnabled(false);
        btn_refresh.setVisible(false);
        txtA_custCode.setBackground(new Color(238, 238, 238));
        txt_display.setBackground(new Color(255, 255, 255));
        check_custCode.setForeground(new Color(153,153,153));
        btn_refresh.setForeground(new Color(153,153,153));
        //-------------------------------------
        txt_display.setText("");
        txtA_custCode.setText("");
        check_custCode.setSelected(false);
    }
    public String getJavaCodeEquivalent()
    {
        //control if custom code mode is enabled
        if(check_custCode.isSelected()==false)//uncheck
            return translateInputToCode();
        else//check - enable customization of generated code
            return ""+txtA_custCode.getText();
    }
    public String getPseudoCodeEquivalent()
    {
        //control if custom code mode is enabled
        if(check_custCode.isSelected()==false)//uncheck
            return txt_display.getText();
        else//check - enable customization of generated code
            return ""+txtA_custCode.getText();
    }
    public void getVariableList(String[] str,String previousInput)
    {
        cmb_variableList.removeAllItems();
        variable_list = str;
        int i = 0;
        while(variable_list[i]!=null)
        {
            cmb_variableList.addItem(""+variable_list[i]);
            i++;
        }
        reset();
        txt_display.setText(""+trasnlateInputToPseudo(previousInput));
    }
    public void appendInput(String input)
    {
        txt_display.setText(txt_display.getText()+""+input);
    }
    public void backspace()
    {
        String str_i = txt_display.getText();
        String str_r[] = new String[2];//temp
        int length = str_i.length();

        String function_list[] = {"POW","ABS","FLOOR","CEIL","SQRT","ROUND","LOG","EXP",null};
      
        str_r = wordBackspace(variable_list,str_i);//variable backspace
        //function backspace
        if(!str_r[1].equals("true"))
            str_r = wordBackspace(function_list,str_i);
        
        //single backspace
        if(!str_r[1].equals("true"))
        {
            for(int i=0;i<length-1;i++)
            {
                str_r[0] += str_i.charAt(i);//transfer to temp except last
            }
        }
        txt_display.setText(str_r[0]);
        
    }
    public String[] wordBackspace(String list[],String str_i)//list of to-delete words, string to be worked on
    {
        /*pseudo backspace
         ***************LOGIC*********************
         * Given: variables ax,bq & cz
         * Operation: ax+123+cz
         * function: backspace(delete the entire variable if its a variable, delete once if its not.)
         * >search for available variables within the operation "ax+123+cz"
         * >if any variables is found in the last charIndex(index:string.length()) delete it.
         * HOW?
         * >to verifiy if the searched variable is in the last charIndex, retrieve the variable's
         *  last character and compare it to the last character of the operation, if it matches,
         *  delete the entire variable.
         * 
         * KNOWN BUGS:
         * >****SOLVED*****it deletes all identified "words" that are classified as variables for deletion.
         * e.g.: POW(32,1)POW
         * the second POW is a variable,when the DEL button is activated, it also deletes the
         * POW function.
         * 
         * Solution:
         * Delete the entire variable by deleting the last number of characters equivalent to the
         * number of characters in the variable.
         * 
         * Changes:
         * isolated into a function. Unforseen bugs.
        **/
        String str_r[] = new String[2];//temp
        int counter = 0;
        String lastCharOfVar  = "";
        str_r[1]="false";
        str_r[0]="";
        while(list[counter]!=null)
        {
            if(str_i.indexOf(list[counter])>=0) //searches word in a string: T - found, F - not found
            {
               lastCharOfVar = ""+list[counter].charAt(list[counter].length()-1); //searches for the last character in the variable found
               if(lastCharOfVar.equals(""+str_i.charAt(str_i.length()-1)))//verifies if the value of lastCharOfVar is in the last index(char) of display
               {
                   for(int i=0;i<str_i.length()-list[counter].length();i++)
                   {
                       str_r[0]+= str_i.charAt(i);
                   }
                   str_r[1] = "true";//raises flag if a delete occured
                   break;//exit loop to ensure 1 variable is only deleted at a time
               }
            }
            counter++;
        }
        //code bacskpace
        return str_r;
    }
    public void power()
    {
        String str = txt_display.getText();
        //pseudo equivalent
        str = "POW("+str+",";
        txt_display.setText(str);
        
    }
    public void absolute()
    {
        String str = txt_display.getText();
        //pseudo equivalent
        str = "ABS("+str+")";
        txt_display.setText(str);
    }
    public void floor()
    {
        String str = txt_display.getText();
        //pseudo equivalent
        str = "FLOOR("+str+")";
        txt_display.setText(str);
    }
    public void ceil()
    {
        String str = txt_display.getText();
        //pseudo equivalent
        str = "CEIL("+str+")";
        txt_display.setText(str);     
    }
    public void squareRoot()
    {
        String str = txt_display.getText();
        //pseudo equivalent
        str = "SQRT("+str+")";
        txt_display.setText(str);      
    }
    public void round()
    {
        String str = txt_display.getText();
        //pseudo equivalent
        str = "ROUND("+str+")";
        txt_display.setText(str); 
    }
    public void logarithm()
    {
        String str = txt_display.getText();
        //pseudo equivalent
        str = "LOG("+str+")";
        txt_display.setText(str);   
    }
    public void exponential()
    {
        String str = txt_display.getText();
        //pseudo equivalent
        str = "EXP("+str+")";
        txt_display.setText(str);    
    }
    public String translateInputToCode()
    {
        String code = ""+txt_display.getText();
        code = code.replace("POW","Math.pow");
        code = code.replace("ABS","Math.abs");
        code = code.replace("FLOOR","Math.floor");
        code = code.replace("CEIL","Math.ceil");
        code = code.replace("SQRT","Math.sqrt");
        code = code.replace("ROUND","Math.round");
        code = code.replace("LOG","Math.log");
        code = code.replace("EXP","Math.exp");
        return code;
    }
    public String trasnlateInputToPseudo(String pseudo)
    {
        pseudo = pseudo.replace("Math.pow","POW");
        pseudo = pseudo.replace("Math.abs","ABS");
        pseudo = pseudo.replace("Math.floor","FLOOR");
        pseudo = pseudo.replace("Math.ceil","CEIL");
        pseudo = pseudo.replace("Math.sqrt","SQRT");
        pseudo = pseudo.replace("Math.round","ROUND");
        pseudo = pseudo.replace("Math.log","LOG");
        pseudo = pseudo.replace("Math.exp","EXP");     
        return pseudo;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panel_buttons = new javax.swing.JPanel();
        btn_7 = new javax.swing.JButton();
        btn_8 = new javax.swing.JButton();
        btn_9 = new javax.swing.JButton();
        btn_4 = new javax.swing.JButton();
        btn_5 = new javax.swing.JButton();
        btn_6 = new javax.swing.JButton();
        btn_1 = new javax.swing.JButton();
        btn_2 = new javax.swing.JButton();
        btn_3 = new javax.swing.JButton();
        btn_decimal = new javax.swing.JButton();
        btn_0 = new javax.swing.JButton();
        btn_del = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        btn_pow = new javax.swing.JButton();
        btn_abs = new javax.swing.JButton();
        floor = new javax.swing.JButton();
        btn_ceil = new javax.swing.JButton();
        sqrt = new javax.swing.JButton();
        btn_round = new javax.swing.JButton();
        btn_log = new javax.swing.JButton();
        btn_exp = new javax.swing.JButton();
        panel_help = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtA_custCode = new javax.swing.JTextArea();
        jPanel5 = new javax.swing.JPanel();
        check_custCode = new javax.swing.JCheckBox();
        filler4 = new javax.swing.Box.Filler(new java.awt.Dimension(10, 10), new java.awt.Dimension(10, 10), new java.awt.Dimension(10, 10));
        btn_refresh = new javax.swing.JButton();
        filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(3, 3), new java.awt.Dimension(3, 3), new java.awt.Dimension(3, 3));
        jPanel4 = new javax.swing.JPanel();
        filler2 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 23), new java.awt.Dimension(0, 23), new java.awt.Dimension(0, 23));
        btn_done = new javax.swing.JButton();
        filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(5, 5), new java.awt.Dimension(5, 5), new java.awt.Dimension(32767, 5));
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        btn_clear = new javax.swing.JButton();
        btn_mod = new javax.swing.JButton();
        btn_open = new javax.swing.JButton();
        btn_close = new javax.swing.JButton();
        btn_divide = new javax.swing.JButton();
        btn_multi = new javax.swing.JButton();
        btn_add = new javax.swing.JButton();
        btn_minus = new javax.swing.JButton();
        panel_top = new javax.swing.JPanel();
        txt_display = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        filler6 = new javax.swing.Box.Filler(new java.awt.Dimension(5, 5), new java.awt.Dimension(5, 5), new java.awt.Dimension(32767, 0));
        cmb_variableList = new javax.swing.JComboBox();
        filler5 = new javax.swing.Box.Filler(new java.awt.Dimension(5, 5), new java.awt.Dimension(5, 5), new java.awt.Dimension(5, 5));
        btn_insertVariable = new javax.swing.JButton();

        setTitle("Num Pad");
        setAlwaysOnTop(true);
        setBackground(new java.awt.Color(255, 204, 204));
        setResizable(false);
        getContentPane().setLayout(new java.awt.BorderLayout(5, 5));

        panel_buttons.setBackground(new java.awt.Color(204, 255, 204));
        panel_buttons.setMaximumSize(new java.awt.Dimension(180, 137));
        panel_buttons.setMinimumSize(new java.awt.Dimension(180, 137));
        panel_buttons.setPreferredSize(new java.awt.Dimension(180, 137));
        panel_buttons.setRequestFocusEnabled(false);
        panel_buttons.setLayout(new java.awt.GridLayout(4, 3, 5, 5));

        btn_7.setText("7");
        btn_7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_7ActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_7);

        btn_8.setText("8");
        btn_8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_8ActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_8);

        btn_9.setText("9");
        btn_9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_9ActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_9);

        btn_4.setText("4");
        btn_4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_4ActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_4);

        btn_5.setText("5");
        btn_5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_5ActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_5);

        btn_6.setText("6");
        btn_6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_6ActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_6);

        btn_1.setText("1");
        btn_1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_1ActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_1);

        btn_2.setText("2");
        btn_2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_2ActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_2);

        btn_3.setText("3");
        btn_3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_3ActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_3);

        btn_decimal.setText(".");
        btn_decimal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_decimalActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_decimal);

        btn_0.setText("0");
        btn_0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_0ActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_0);

        btn_del.setText("DEL");
        btn_del.setToolTipText("Backspace");
        btn_del.setMaximumSize(new java.awt.Dimension(110, 30));
        btn_del.setMinimumSize(new java.awt.Dimension(110, 30));
        btn_del.setPreferredSize(new java.awt.Dimension(110, 30));
        btn_del.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_delActionPerformed(evt);
            }
        });
        panel_buttons.add(btn_del);

        getContentPane().add(panel_buttons, java.awt.BorderLayout.CENTER);

        jPanel3.setBackground(new java.awt.Color(204, 204, 255));
        jPanel3.setMaximumSize(new java.awt.Dimension(170, 137));
        jPanel3.setMinimumSize(new java.awt.Dimension(170, 137));
        jPanel3.setPreferredSize(new java.awt.Dimension(170, 137));
        jPanel3.setLayout(new java.awt.GridLayout(4, 2, 5, 5));

        btn_pow.setText("POW");
        btn_pow.setToolTipText("Power");
        btn_pow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_powActionPerformed(evt);
            }
        });
        jPanel3.add(btn_pow);

        btn_abs.setText("ABS");
        btn_abs.setToolTipText("Absolute");
        btn_abs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_absActionPerformed(evt);
            }
        });
        jPanel3.add(btn_abs);

        floor.setText("FLOOR");
        floor.setToolTipText("Floor");
        floor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                floorActionPerformed(evt);
            }
        });
        jPanel3.add(floor);

        btn_ceil.setText("CEIL");
        btn_ceil.setToolTipText("Ceiling");
        btn_ceil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ceilActionPerformed(evt);
            }
        });
        jPanel3.add(btn_ceil);

        sqrt.setText("SQRT");
        sqrt.setToolTipText("Square Root");
        sqrt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sqrtActionPerformed(evt);
            }
        });
        jPanel3.add(sqrt);

        btn_round.setText("ROUND");
        btn_round.setToolTipText("Round off");
        btn_round.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_roundActionPerformed(evt);
            }
        });
        jPanel3.add(btn_round);

        btn_log.setText("LOG");
        btn_log.setToolTipText("Logarithm");
        btn_log.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_logActionPerformed(evt);
            }
        });
        jPanel3.add(btn_log);

        btn_exp.setText("EXP");
        btn_exp.setToolTipText("Exponential");
        btn_exp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_expActionPerformed(evt);
            }
        });
        jPanel3.add(btn_exp);

        getContentPane().add(jPanel3, java.awt.BorderLayout.LINE_START);

        panel_help.setMinimumSize(new java.awt.Dimension(189, 65));
        panel_help.setPreferredSize(new java.awt.Dimension(211, 95));
        panel_help.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.TRAILING, 0, 0));

        jPanel2.setBorder(javax.swing.BorderFactory.createCompoundBorder());
        jPanel2.setLayout(new java.awt.BorderLayout());

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        txtA_custCode.setColumns(32);
        txtA_custCode.setLineWrap(true);
        txtA_custCode.setRows(4);
        txtA_custCode.setWrapStyleWord(true);
        txtA_custCode.setAutoscrolls(false);
        txtA_custCode.setBorder(null);
        jScrollPane1.setViewportView(txtA_custCode);

        jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jPanel5.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel5.setLayout(new javax.swing.BoxLayout(jPanel5, javax.swing.BoxLayout.LINE_AXIS));

        check_custCode.setForeground(new java.awt.Color(153, 153, 153));
        check_custCode.setText("Customize Code (JAVA)");
        check_custCode.setToolTipText("Enable/Disable Code Customization Option");
        check_custCode.setBorder(null);
        check_custCode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                check_custCodeActionPerformed(evt);
            }
        });
        jPanel5.add(check_custCode);
        jPanel5.add(filler4);

        btn_refresh.setForeground(new java.awt.Color(0, 0, 153));
        btn_refresh.setText(" Refresh ");
        btn_refresh.setToolTipText("Reset Code");
        btn_refresh.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        btn_refresh.setContentAreaFilled(false);
        btn_refresh.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btn_refreshMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btn_refreshMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                btn_refreshMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                btn_refreshMouseReleased(evt);
            }
        });
        btn_refresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_refreshActionPerformed(evt);
            }
        });
        jPanel5.add(btn_refresh);

        jPanel2.add(jPanel5, java.awt.BorderLayout.PAGE_START);

        panel_help.add(jPanel2);
        panel_help.add(filler1);

        jPanel4.setMaximumSize(new java.awt.Dimension(105, 70));
        jPanel4.setMinimumSize(new java.awt.Dimension(105, 70));
        jPanel4.setPreferredSize(new java.awt.Dimension(105, 90));
        jPanel4.setRequestFocusEnabled(false);
        jPanel4.setLayout(new javax.swing.BoxLayout(jPanel4, javax.swing.BoxLayout.PAGE_AXIS));
        jPanel4.add(filler2);

        btn_done.setText("Done");
        btn_done.setMaximumSize(new java.awt.Dimension(100, 29));
        btn_done.setMinimumSize(new java.awt.Dimension(100, 29));
        btn_done.setPreferredSize(new java.awt.Dimension(100, 29));
        btn_done.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_doneActionPerformed(evt);
            }
        });
        jPanel4.add(btn_done);
        jPanel4.add(filler3);

        jButton2.setText("EXIT");
        jButton2.setMaximumSize(new java.awt.Dimension(100, 29));
        jButton2.setMinimumSize(new java.awt.Dimension(100, 29));
        jButton2.setPreferredSize(new java.awt.Dimension(100, 29));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel4.add(jButton2);

        panel_help.add(jPanel4);

        getContentPane().add(panel_help, java.awt.BorderLayout.PAGE_END);

        jPanel1.setBackground(new java.awt.Color(255, 255, 204));
        jPanel1.setMaximumSize(new java.awt.Dimension(110, 137));
        jPanel1.setMinimumSize(new java.awt.Dimension(110, 137));
        jPanel1.setPreferredSize(new java.awt.Dimension(110, 137));
        jPanel1.setLayout(new java.awt.GridLayout(4, 2, 5, 5));

        btn_clear.setText("C");
        btn_clear.setToolTipText("Clear");
        btn_clear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_clearActionPerformed(evt);
            }
        });
        jPanel1.add(btn_clear);

        btn_mod.setText("%");
        btn_mod.setToolTipText("Modulo");
        btn_mod.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_modActionPerformed(evt);
            }
        });
        jPanel1.add(btn_mod);

        btn_open.setText("(");
        btn_open.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_openActionPerformed(evt);
            }
        });
        jPanel1.add(btn_open);

        btn_close.setText(")");
        btn_close.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_closeActionPerformed(evt);
            }
        });
        jPanel1.add(btn_close);

        btn_divide.setText("/");
        btn_divide.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_divideActionPerformed(evt);
            }
        });
        jPanel1.add(btn_divide);

        btn_multi.setText("x");
        btn_multi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_multiActionPerformed(evt);
            }
        });
        jPanel1.add(btn_multi);

        btn_add.setText("+");
        btn_add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_addActionPerformed(evt);
            }
        });
        jPanel1.add(btn_add);

        btn_minus.setText("-");
        btn_minus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_minusActionPerformed(evt);
            }
        });
        jPanel1.add(btn_minus);

        getContentPane().add(jPanel1, java.awt.BorderLayout.LINE_END);

        panel_top.setLayout(new javax.swing.BoxLayout(panel_top, javax.swing.BoxLayout.Y_AXIS));

        txt_display.setColumns(58);
        txt_display.setEditable(false);
        txt_display.setFont(new java.awt.Font("Courier New", 1, 14));
        txt_display.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        txt_display.setText("test test 01234567890(pow)");
        txt_display.setMaximumSize(new java.awt.Dimension(470, 33));
        txt_display.setMinimumSize(new java.awt.Dimension(470, 33));
        txt_display.setPreferredSize(new java.awt.Dimension(470, 33));
        panel_top.add(txt_display);

        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.TRAILING, 1, 3));

        jLabel1.setText("   Variable : ");
        jPanel6.add(jLabel1);
        jPanel6.add(filler6);

        cmb_variableList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmb_variableList.setPreferredSize(new java.awt.Dimension(178, 23));
        jPanel6.add(cmb_variableList);
        jPanel6.add(filler5);

        btn_insertVariable.setText("       Insert       ");
        btn_insertVariable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_insertVariableActionPerformed(evt);
            }
        });
        jPanel6.add(btn_insertVariable);

        panel_top.add(jPanel6);

        getContentPane().add(panel_top, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_ceilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ceilActionPerformed
        // TODO add your handling code here:
        ceil();
    }//GEN-LAST:event_btn_ceilActionPerformed

    private void btn_doneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_doneActionPerformed
        // TODO add your handling code here:
       
       this.setVisible(false);
    }//GEN-LAST:event_btn_doneActionPerformed

    private void btn_1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_1ActionPerformed
        // TODO add your handling code here:
        appendInput("1");
    }//GEN-LAST:event_btn_1ActionPerformed

    private void btn_2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_2ActionPerformed
        // TODO add your handling code here:
        appendInput("2");
    }//GEN-LAST:event_btn_2ActionPerformed

    private void btn_3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_3ActionPerformed
        // TODO add your handling code here:
        appendInput("3");
    }//GEN-LAST:event_btn_3ActionPerformed

    private void btn_4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_4ActionPerformed
        // TODO add your handling code here:
        appendInput("4");
    }//GEN-LAST:event_btn_4ActionPerformed

    private void btn_5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_5ActionPerformed
        // TODO add your handling code here:
        appendInput("5");
    }//GEN-LAST:event_btn_5ActionPerformed

    private void btn_6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_6ActionPerformed
        // TODO add your handling code here:
        appendInput("6");
    }//GEN-LAST:event_btn_6ActionPerformed

    private void btn_7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_7ActionPerformed
        // TODO add your handling code here:
        appendInput("7");
    }//GEN-LAST:event_btn_7ActionPerformed

    private void btn_8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_8ActionPerformed
        // TODO add your handling code here:
        appendInput("8");
    }//GEN-LAST:event_btn_8ActionPerformed

    private void btn_9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_9ActionPerformed
        // TODO add your handling code here:
        appendInput("9");
    }//GEN-LAST:event_btn_9ActionPerformed

    private void btn_0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_0ActionPerformed
        // TODO add your handling code here:
        appendInput("0");
    }//GEN-LAST:event_btn_0ActionPerformed

    private void btn_decimalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_decimalActionPerformed
        // TODO add your handling code here:
        appendInput(".");
    }//GEN-LAST:event_btn_decimalActionPerformed

    private void check_custCodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_check_custCodeActionPerformed
        // TODO add your handling code here:
        if(check_custCode.isSelected()==false)//uncheck
        {
            //UI customizations
            txtA_custCode.setText("");
            txtA_custCode.setEnabled(false);
            txt_display.setEnabled(true);
            btn_refresh.setEnabled(false);
            btn_refresh.setVisible(false);
            txtA_custCode.setBackground(new Color(238, 238, 238));//disable mode GRAY
            txt_display.setBackground(new Color(255, 255, 255));//enable mode WHITE
            check_custCode.setForeground(new Color(153,153,153));//disable mode GRAY
            btn_refresh.setForeground(new Color(153,153,153));//disable mode GRAY

        }else//check - enable customization of generated code
        {
            //UI customizations
            txtA_custCode.setEnabled(true);
            txt_display.setEnabled(false);
            btn_refresh.setEnabled(true);
            btn_refresh.setVisible(true);
            txtA_custCode.setBackground(new Color(255, 255, 255));//enable mode WHITE
            txt_display.setBackground(new Color(238, 238, 238));//disable mode GRAY
            check_custCode.setForeground(new Color(0,0,0));//enable mode BLACK
            btn_refresh.setForeground(new Color(153,153,255));//enable mode LIGHT BLUE
            
            txtA_custCode.setText(translateInputToCode());
        }
    }//GEN-LAST:event_check_custCodeActionPerformed

    private void btn_clearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_clearActionPerformed
        // TODO add your handling code here:
        reset();
    }//GEN-LAST:event_btn_clearActionPerformed

    private void btn_modActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_modActionPerformed
        // TODO add your handling code here:
        appendInput("%");
    }//GEN-LAST:event_btn_modActionPerformed

    private void btn_openActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_openActionPerformed
        // TODO add your handling code here:
        appendInput("(");
    }//GEN-LAST:event_btn_openActionPerformed

    private void btn_closeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_closeActionPerformed
        // TODO add your handling code here:
        appendInput(")");
    }//GEN-LAST:event_btn_closeActionPerformed

    private void btn_divideActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_divideActionPerformed
        // TODO add your handling code here:
        appendInput("/");
    }//GEN-LAST:event_btn_divideActionPerformed

    private void btn_multiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_multiActionPerformed
        // TODO add your handling code here:
        appendInput("*");
    }//GEN-LAST:event_btn_multiActionPerformed

    private void btn_addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_addActionPerformed
        // TODO add your handling code here:
        appendInput("+");
    }//GEN-LAST:event_btn_addActionPerformed

    private void btn_minusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_minusActionPerformed
        // TODO add your handling code here:
        appendInput("-");
    }//GEN-LAST:event_btn_minusActionPerformed

    private void btn_delActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_delActionPerformed
        backspace();
    }//GEN-LAST:event_btn_delActionPerformed

    private void btn_powActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_powActionPerformed
        // TODO add your handling code here:
        power();
    }//GEN-LAST:event_btn_powActionPerformed

    private void btn_refreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_refreshActionPerformed
        // TODO add your handling code here:
        if(btn_refresh.isEnabled()==true)
            txtA_custCode.setText(translateInputToCode());
    }//GEN-LAST:event_btn_refreshActionPerformed

    private void btn_refreshMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_refreshMouseEntered
        if(btn_refresh.isEnabled()==true)
            btn_refresh.setForeground(new Color(51,51,255));//hover[51,51,255]
    }//GEN-LAST:event_btn_refreshMouseEntered

    private void btn_refreshMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_refreshMouseExited
        // TODO add your handling code here:
        if(btn_refresh.isEnabled()==true)
            btn_refresh.setForeground(new Color(153,153,255));//return to normal LIGHT BLUE
    }//GEN-LAST:event_btn_refreshMouseExited

    private void btn_refreshMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_refreshMousePressed
        // TODO add your handling code here:[0,0,153]
         if(btn_refresh.isEnabled()==true)
            btn_refresh.setForeground(new Color(0,0,153));//press = [0,0,153]      
    }//GEN-LAST:event_btn_refreshMousePressed

    private void btn_refreshMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_refreshMouseReleased
        // TODO add your handling code here:
        if(btn_refresh.isEnabled()==true)
            btn_refresh.setForeground(new Color(51,51,255));//hover[51,51,255]
    }//GEN-LAST:event_btn_refreshMouseReleased

    private void btn_insertVariableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_insertVariableActionPerformed
        // TODO add your handling code here:
        appendInput(""+cmb_variableList.getSelectedItem());
    }//GEN-LAST:event_btn_insertVariableActionPerformed

    private void btn_absActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_absActionPerformed
        // TODO add your handling code here:
        absolute();
    }//GEN-LAST:event_btn_absActionPerformed

    private void floorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_floorActionPerformed
        // TODO add your handling code here:
        floor();
    }//GEN-LAST:event_floorActionPerformed

    private void sqrtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sqrtActionPerformed
        // TODO add your handling code here:
        squareRoot();
    }//GEN-LAST:event_sqrtActionPerformed

    private void btn_roundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_roundActionPerformed
        // TODO add your handling code here:
        round();
    }//GEN-LAST:event_btn_roundActionPerformed

    private void btn_logActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_logActionPerformed
        // TODO add your handling code here:
        logarithm();
    }//GEN-LAST:event_btn_logActionPerformed

    private void btn_expActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_expActionPerformed
        // TODO add your handling code here:
        exponential();
    }//GEN-LAST:event_btn_expActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        reset();
        this.setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        
    }
    //custom declared variables
    String[] variable_list = new String[100];
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_0;
    private javax.swing.JButton btn_1;
    private javax.swing.JButton btn_2;
    private javax.swing.JButton btn_3;
    private javax.swing.JButton btn_4;
    private javax.swing.JButton btn_5;
    private javax.swing.JButton btn_6;
    private javax.swing.JButton btn_7;
    private javax.swing.JButton btn_8;
    private javax.swing.JButton btn_9;
    private javax.swing.JButton btn_abs;
    private javax.swing.JButton btn_add;
    private javax.swing.JButton btn_ceil;
    private javax.swing.JButton btn_clear;
    private javax.swing.JButton btn_close;
    private javax.swing.JButton btn_decimal;
    private javax.swing.JButton btn_del;
    private javax.swing.JButton btn_divide;
    private javax.swing.JButton btn_done;
    private javax.swing.JButton btn_exp;
    private javax.swing.JButton btn_insertVariable;
    private javax.swing.JButton btn_log;
    private javax.swing.JButton btn_minus;
    private javax.swing.JButton btn_mod;
    private javax.swing.JButton btn_multi;
    private javax.swing.JButton btn_open;
    private javax.swing.JButton btn_pow;
    private javax.swing.JButton btn_refresh;
    private javax.swing.JButton btn_round;
    private javax.swing.JCheckBox check_custCode;
    private javax.swing.JComboBox cmb_variableList;
    private javax.swing.Box.Filler filler1;
    private javax.swing.Box.Filler filler2;
    private javax.swing.Box.Filler filler3;
    private javax.swing.Box.Filler filler4;
    private javax.swing.Box.Filler filler5;
    private javax.swing.Box.Filler filler6;
    private javax.swing.JButton floor;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel panel_buttons;
    private javax.swing.JPanel panel_help;
    private javax.swing.JPanel panel_top;
    private javax.swing.JButton sqrt;
    private javax.swing.JTextArea txtA_custCode;
    private javax.swing.JTextField txt_display;
    // End of variables declaration//GEN-END:variables
}
